$(function () {
	Vue.http.options.emulateJSON = true;
	
	$('input[name="onWork"]').timepicker({
        timeFormat: 'HH:mm:ss',
        minHour: 0,
        maxHour: 12,
        maxMinutes: 59,
        startTime: '00:00:00',
        interval: 10,
        dynamic: false,
        scrollbar: true
    });
	
	$('input[name="offWork"]').timepicker({
		timeFormat: 'HH:mm:ss',
        minHour: 13,
        maxHour: 23,
        maxMinutes: 59,
        startTime: '13:00:00',
        interval: 10,
        dynamic: false,
        scrollbar: true
    });
	
	$(".required-validate").validate({
		errorElement : "label",  
        errorClass : "text-danger",  
        rules : {  
        	onWork : {  
            	required : true,
            	minlength: 8,
            	maxlength: 8
            },
            offWork : {
            	required : true,
            	minlength: 8,
            	maxlength: 8
            },
            allowLate: {
            	required: true,
                digits : true
            },
            allowLeave: {
            	required: true,
                digits : true
            }
        },
        submitHandler: function(form) {
        	$.showloading();
        	Vue.http.post(
				"attendance/setting", 
				{
					onWork : $('input[name="onWork"]').val(),
		            offWork : $('input[name="offWork"]').val(),
		            allowLate: $('input[name="allowLate"]').val(),
		            allowLeave: $('input[name="allowLeave"]').val()
				}
			).then((res) => {
				var data = res.data; 
				console.log(data);
				
				bootbox.alert({
				    message: data.msg,
				    size: 'small'
				});
			}, (res) => {
				bootbox.alert({
				    message: "系统错误",
				    size: 'small'
				});
			}).finally((res) => {
				$.hideloading();
			});
		}
	});
})